-
Notifications
You must be signed in to change notification settings - Fork 30
Draft: Add Puppet proxy (CA) bulk actions #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
adamruzicka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some notes inline, can't speak much to the frontend
| extend ActiveSupport::Concern | ||
|
|
||
| included do | ||
| before_action :find_editable_hosts, :only => [:change_puppet_proxy] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this override the before action from the base class in https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/hosts_bulk_actions_controller.rb#L8 ?
In this case I'd prefer katello's approach - have a brand new controller rather than trying to extend the existing one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it does. Is there a way not to overwrite it? If not, it has to be a new controller, indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the top of my head I can't suggest any clean way that would make it behave the way we need. Hacks could be done, sure, with the cleanest one probably being just calling it directly in #change_puppet_proxy without relying on controller callbacks.
|
|
||
| api :PUT, "/hosts/bulk/change_puppet_proxy", N_("Change Puppet Proxy") | ||
| param_group :bulk_host_ids | ||
| param :proxy_id, :number, :required => true, :desc => N_("ID of the Puppet proxy to reassign the hosts to") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This being required means it can be used to reassign the host to a different proxy, but this cannot be used to unassign it, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I have not yet implemented the unassign method, so the implementation details about that one are still open.
| host.puppet_ca_proxy = proxy | ||
| else | ||
| host.puppet_proxy = proxy | ||
| end | ||
| host.save(:validate => false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need callbacks to be run or could we take a shortcut and assign the proxy with a single update query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, if we need callbacks to be honest. The original action does run some validations about validating the proxy I think: https://github.com/theforeman/foreman_puppet/blob/master/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb#L143
Can the update command also take the validate => false parameter?
| rescue StandardError => e | ||
| message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type) | ||
| Foreman::Logging.exception(message, e) | ||
| end | ||
| rescue RecordNotFoundError => e | ||
| Foreman::Logging.exception(_('Cound not find Smart Proxy')) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| rescue StandardError => e | |
| message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type) | |
| Foreman::Logging.exception(message, e) | |
| end | |
| rescue RecordNotFoundError => e | |
| Foreman::Logging.exception(_('Cound not find Smart Proxy')) | |
| end | |
| rescue StandardError => e | |
| message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type) | |
| Foreman::Logging.exception(message, e) | |
| end | |
| rescue ActiveRecord::RecordNotFound => e | |
| Foreman::Logging.exception(_('Cound not find Smart Proxy')) | |
| end |
And even then, ActiveRecord::RecordNotFound is a subclass of StandardError so the record not found branch would never match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that one is messy - this also somehow depends if we want a separate method for unassign.
| extend ActiveSupport::Concern | ||
|
|
||
| def change_puppet_proxy(proxy_id, ca_proxy) | ||
| proxy = SmartProxy.find_by(id: proxy_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just returns nil if no proxy was found. Is that expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I would solve that depending on how I implement the unassign method. The PR is still very drafty.
e2b1c7f to
c7dd83c
Compare
nadjaheitmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @adamruzicka !
| extend ActiveSupport::Concern | ||
|
|
||
| included do | ||
| before_action :find_editable_hosts, :only => [:change_puppet_proxy] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it does. Is there a way not to overwrite it? If not, it has to be a new controller, indeed.
|
|
||
| api :PUT, "/hosts/bulk/change_puppet_proxy", N_("Change Puppet Proxy") | ||
| param_group :bulk_host_ids | ||
| param :proxy_id, :number, :required => true, :desc => N_("ID of the Puppet proxy to reassign the hosts to") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I have not yet implemented the unassign method, so the implementation details about that one are still open.
| extend ActiveSupport::Concern | ||
|
|
||
| def change_puppet_proxy(proxy_id, ca_proxy) | ||
| proxy = SmartProxy.find_by(id: proxy_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I would solve that depending on how I implement the unassign method. The PR is still very drafty.
| host.puppet_ca_proxy = proxy | ||
| else | ||
| host.puppet_proxy = proxy | ||
| end | ||
| host.save(:validate => false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, if we need callbacks to be honest. The original action does run some validations about validating the proxy I think: https://github.com/theforeman/foreman_puppet/blob/master/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb#L143
Can the update command also take the validate => false parameter?
| rescue StandardError => e | ||
| message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type) | ||
| Foreman::Logging.exception(message, e) | ||
| end | ||
| rescue RecordNotFoundError => e | ||
| Foreman::Logging.exception(_('Cound not find Smart Proxy')) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that one is messy - this also somehow depends if we want a separate method for unassign.
ac62ab7 to
e980546
Compare
11c8919 to
4512e86
Compare
4512e86 to
2eb2f1a
Compare
c057e40 to
4bb7ef6
Compare
4bb7ef6 to
0faf7d6
Compare
@adamruzicka @jeremylenz I have created a draft for the Puppet Proxy update bulk action. It is not more than a draft and I know there is a bunch of things missing (e.g. clearing proxy, CA proxy, tests, ...). I basically took code from Foreman and Katello and mixed it into this. Do you mind checking whether the general approach is the direction we want to go. UI wise, I think this is straight forward, but I was not sure whether
is the way to go.
I appreciate your opinions.